/**
 * interactioin-util.js
 * 
 * todo 按钮的一些处理
 */
//线路计时器
var timers = new Array(2);

TimerObj = function() {
    this.second = 0;
	this.minute = 0;
	this.hour = 0;
	this.timeoutObj = null;
	
};

function showTimer(key){
	var timerObj = timers[key];
	if(timerObj == null || timerObj == undefined){
		timerObj = new TimerObj();
	}
	//alert("show");
	timerObj.second++; 
    if (timerObj.second == 60) {
        timerObj.second = 0;
        timerObj.minute += 1;
    }
    if (timerObj.minute == 60) {
        timerObj.minute = 0;
        timerObj.hour += 1;
    }
	timerObj.timeValue = ((timerObj.minute < 10) ? "0" : "") + timerObj.minute;
	timerObj.timeValue += ((timerObj.second < 10) ? ":0" : ":") + timerObj.second;
	timerObj.timeValue = ((timerObj.hour < 10) ? "0" : "") + timerObj.hour + ":" + timerObj.timeValue;
	//alert(timerObj.timeValue);
	$("#timer"+key).html(timerObj.timeValue);
	timerObj.timeoutObj = setTimeout("showTimer("+key+")", 1000);
	timers[key]=timerObj;
	//alert(timers[key].timeoutObj);
};
function stopTimer(key){
	clearTimeout(timers[key].timeoutObj);
	timers[key] = null;
    $("#timer"+key).html("00:00:00");
};

function startTimer(key){
	var timeObj = timers[key];
	if(timeObj == null) {
		showTimer(key);
	}
};


$(function() {

	// 签入、签出
	$("#btnLogin").click(function() {
		if ($(this).hasClass("disable")) {
			return;
		}
		login1();
		//showButtons(2);
	});
	$("#btnLogout").click(function() {
		if ($(this).hasClass("disable")) {
			return;
		}
		logout1();
		//showButtons(6);
	});
	// 就绪、未就绪
	$("#btnReady").click(function() {
		if ($(this).hasClass("disable")) {
			return;
		}
		ready1();
		//showButtons(3);
	});
	$("#btnNotReady").click(function() {
		if ($(this).hasClass("disable")) {
			return;
		}
		notReady1();
		//showButtons(4);
	});
	//小休
	$(".btns-rest").click(function(){
		if ($(this).hasClass("disable")) {
			return;
		}
		if(agentStatus != "Ready") {
			return;
		}
		var reasonCode = $(".sel-rest").val();
		if(reasonCode<1){
			alert('请选择小休原因');
			return false;
		}
		notReady("voice",reasonCode,workMode);
	})
	// 呼叫
	$("#btnCall").click(function() {
        if ($(this).hasClass("disable")) {
            return;
        }
		var phoneNumber = $("#phoneNo").val();
		if (phoneNumber == null || phoneNumber.length < 1) {
			alert('请输入号码');
			return;
		}
		//showButtons(7);
		makeCall1(phoneNumber);
		//$("#phoneNo").val("");
		///hideNumKeys();
	});
	
	// 接听
	$("#answer").click(function() {
		if($(this).attr("src").indexOf("disable") > -1) {
			return;
		}
		answerCall1();
		//showButtons(9);
	});

	// 挂机
	$("#refuse").click(function() {
		if($(this).attr("src").indexOf("disable") > -1) {
			return;
		}
		releaseCall1();
		//showButtons(13);
	
	});
	
	
	//数字键的隐藏和显示
	var isShow = false;
	$(".numkeys").hide();
	function hideNumKeys() {
		isShow = false;
		$(".numkeys").hide();
	}
	function showNumKeys() {
		isShow = true;
		$(".numkeys").show();
	}
	$(".phonefast img").click(function() {
		//if(agentStatus!="Ready") {
		//	return;
		//}
		if (isShow == false) {
			showNumKeys();
		} else {
			hideNumKeys();
		}
	});
	
	//数字键盘的值
	var num = "";
	$("#phoneNo").change(function() {
		num = $(this).val();
	});
	$(".numkeys-list ul li").click(function() {
		num += $(this).html().replace(/(^\s*)|(\s*$)/g, "");
		$("#phoneNo").val(num);
	});
	
});

